package com.ciei.dpagm.common.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.ciei.dpagm.util.APP;
import com.ciei.dpagm.util.ConvertUtil;
import com.ciei.dpagm.common.mapper.ExpandBaseMapper;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.*;

public class BaseService<M extends ExpandBaseMapper<T>, T> extends ServiceImpl<M, T> {

    /**
     * 根据主键查询
     *
     * @param id 主键id
     */
    public T findById(java.io.Serializable id) {
        return getById(id);
    }

    /**
     * 根据主键集合查询
     * @param idList
     * @return
     */
    public List<T> findListByIds(Collection<? extends Serializable> idList) {
        if (idList == null || idList.isEmpty()){
            return new ArrayList<>();
        }
        return new ArrayList<>(listByIds(idList));
    }

    /**
     * 查询全部记录
     */
    public List<T> findAll() {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        return list(wrapper);
    }

    /**
     * 单条件等值查询，返回一条记录 <br/>
     * 如果是多个结果会抛出异常
     *
     * @param propertyName 属性名
     * @param value        属性值
     */
    public T findOneByProperty(String propertyName, Object value) {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        if (value != null) {
            wrapper.eq(ConvertUtil.humpToLine(propertyName), value);
        } else {
            wrapper.isNull(ConvertUtil.humpToLine(propertyName));
        }
        return (T) getOne(wrapper);
    }

    /**
     * 单条件等值查询
     *
     * @param propertyName 属性名
     * @param value        属性值
     * @return 满足条件的所有记录
     */
    public List<T> findByProperty(String propertyName, Object value) {

        QueryWrapper<T> wrapper = new QueryWrapper<>();
        if (value != null) {
            wrapper.eq(ConvertUtil.humpToLine(propertyName), value);
        } else {
            wrapper.isNull(ConvertUtil.humpToLine(propertyName));
        }
        return list(wrapper);
    }

    /**
     * 单条件等值查询
     * @param equalField 获取列名的函数
     * @param value 值
     * @return 满足条件的所有记录
     */
    public List<T> findByProperty(SFunction<T, ?> equalField, Object value) {
        LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(equalField, value);
        return list(wrapper);
    }

    /**
     * 多条件等值查询，返回一条记录 <br/>
     * 如果是多个结果会抛出异常
     *
     * @param propertyNames 属性名数组
     * @param values        属性值数组
     */
    public T findOneByProperties(String[] propertyNames, Object[] values) {
        QueryWrapper<T> wrapper = getEqualWrapper(propertyNames, values);
        return (T) getOne(wrapper);
    }

    /**
     * 多条件等值查询
     *
     * @param propertyNames 属性名数组
     * @param values        属性值数组
     * @return 满足条件的所有记录
     */
    public List<T> findByProperties(String[] propertyNames, Object[] values) {
        QueryWrapper<T> wrapper = getEqualWrapper(propertyNames, values);
        return list(wrapper);
    }

    /**
     * 多字段等值查询,返回一条记录 <br/>
     * 如果是多个结果会抛出异常
     *
     * @param fieldValueMap key 是属性的getter, value 是属性值
     * @return 返回一条记录
     */
    public T findOneByProperties(Map<SFunction<T, ?>, Object> fieldValueMap) {
        LambdaQueryWrapper<T> wrapper = getEqualWrapper(fieldValueMap);
        return getOne(wrapper);
    }

    /**
     * 多字段等值查询
     *
     * @param fieldValueMap key 是属性的getter, value 是属性值
     * @return 满足条件的所有记录
     */
    public List<T> findByProperties(Map<SFunction<T, ?>, Object> fieldValueMap) {
        LambdaQueryWrapper<T> wrapper = getEqualWrapper(fieldValueMap);
        return list(wrapper);
    }

    /**
     * 多字段等值查询记录数
     *
     * @param fieldValueMap key 是属性的getter, value 是属性值
     * @return 满足条件的记录数
     */
    public int countByProperties(Map<SFunction<T, ?>, Object> fieldValueMap) {
        LambdaQueryWrapper<T> wrapper = getEqualWrapper(fieldValueMap);
        return count(wrapper);
    }

    public QueryWrapper<T> getEqualWrapper(String[] propertyNames, Object[] values) {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        propertyNames = ConvertUtil.humpToLines(propertyNames);
        if (propertyNames != null) {
            for (int i = 0; i < propertyNames.length; i++) {
                if (values[i] != null) {
                    wrapper.eq(propertyNames[i], values[i]);
                } else {
                    wrapper.isNull(propertyNames[i]);
                }
            }
        }
        return wrapper;
    }

    public LambdaQueryWrapper<T> getEqualWrapper(Map<SFunction<T, ?>, Object> fieldValueMap) {
        LambdaQueryWrapper<T> wrapper = Wrappers.lambdaQuery();
        if (fieldValueMap != null) {
            fieldValueMap.forEach((fieldName, value) -> {
                if (value != null) {
                    wrapper.eq(fieldName, value);
                } else {
                    wrapper.isNull(fieldName);
                }
            });
        }
        return wrapper;
    }

    /**
     * 分页查询
     *
     * @param posStart    起始位置（从0开始）
     * @param pageSize    当前页条数
     * @param params      参数值
     * @param likeFields  like参数
     * @param equalFields 等值参数
     * @param sortFields  排序参数
     */
    public List<T> findPage(int posStart, int pageSize, Map<String, Object> params, String[] likeFields,
                            String[] equalFields, String sortFields) {
        return findPage(posStart, pageSize, params, likeFields, equalFields, sortFields, null);

    }

    /**
     * 分页查询
     *
     * @param posStart    起始位置（从0开始）
     * @param pageSize    当前页条数
     * @param params      参数条件值
     * @param likeFields  like参数
     * @param equalFields 等值参数
     * @param sortFields  排序参数
     * @param inFields    in 参数
     */
    public List<T> findPage(int posStart, int pageSize, Map<String, Object> params, String[] likeFields,
                            String[] equalFields, String sortFields, String[] inFields) {
        IPage<T> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(posStart / pageSize + 1);

        QueryWrapper<T> wrapper = new QueryWrapper<>();
        params = ConvertUtil.humpToLines(params);
        equalFields = ConvertUtil.humpToLines(equalFields);
        likeFields = ConvertUtil.humpToLines(likeFields);
        sortFields = ConvertUtil.humpToLine(sortFields);
        inFields = ConvertUtil.humpToLines(inFields);

        if (equalFields != null) {
            for (String equalField : equalFields) {
                if (params.containsKey(equalField)) {
                    if (params.get(equalField) != null) {
                        wrapper.eq(equalField, params.get(equalField));
                    } else {
                        wrapper.isNull(equalField);
                    }
                }
            }
        }
        if (likeFields != null) {
            for (String likeField : likeFields) {
                if (params.containsKey(likeField) && params.get(likeField) != null) {
                    wrapper.like(likeField, params.get(likeField));
                }
            }
        }
        if (inFields != null) {
            for (String inField : inFields) {
                if (params.containsKey(inField) && params.get(inField) != null) {
                    wrapper.in(inField, Arrays.asList(params.get(inField).toString().split(",")));
                }
            }
        }

        if (sortFields.length() != 0) {
            for (String s : sortFields.split(",")) {
                s = ConvertUtil.humpToLine(s);
                String orderDirect = "";
                if (s.toLowerCase().contains("desc") || s.toLowerCase().contains("asc")) {
                    if (s.toLowerCase().contains("desc")) {
                        orderDirect = "desc";
                    } else {
                        orderDirect = "asc";
                    }
                    s = s.substring(0, s.indexOf(" "));
                } else {
                    orderDirect = "asc";
                }
                if ("asc".equals(orderDirect)) {
                    wrapper.orderByAsc(s);
                } else {
                    wrapper.orderByDesc(s);
                }
            }
        }

        IPage<T> pageR = page(page, wrapper);
        return pageR.getRecords();

    }
    /**
     * 分页查询
     *
     * @param currentPage 当前页码
     * @param pageSize    当前页条数
     * @param params      参数条件值
     * @param likeFields  like参数
     * @param equalFields 等值参数
     * @param sortFields  排序参数
     * @param inFields    in 参数
     */
    public IPage<T> findPageVue(int currentPage, int pageSize, Map<String, Object> params, String[] likeFields,
                            String[] equalFields, Map<String,Object> sortFields, String[] inFields) {
        IPage<T> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(currentPage);

        QueryWrapper<T> wrapper = new QueryWrapper<>();
        params = ConvertUtil.humpToLines(params);
        equalFields = ConvertUtil.humpToLines(equalFields);
        likeFields = ConvertUtil.humpToLines(likeFields);
        sortFields = ConvertUtil.humpToLines(sortFields);
        inFields = ConvertUtil.humpToLines(inFields);

        if (equalFields != null) {
            for (String equalField : equalFields) {
                if (params.containsKey(equalField)) {
                    if (params.get(equalField) != null) {
                        wrapper.eq(equalField, params.get(equalField));
                    } else {
                        wrapper.isNull(equalField);
                    }
                }
            }
        }
        if (likeFields != null) {
            for (String likeField : likeFields) {
                if (params.containsKey(likeField) && params.get(likeField) != null) {
                    wrapper.like(likeField, params.get(likeField));
                }
            }
        }
        if (inFields != null) {
            for (String inField : inFields) {
                List<Object> inList = ((List<Object>) params.get(inField));
                if (inList != null && inList.size() > 0) {
                    wrapper.in(inField, inList);
                }
            }
        }

        if (sortFields!= null) {
            for (Map.Entry<String,Object> entry : sortFields.entrySet()) {
                String sortField = ConvertUtil.humpToLine(entry.getKey());;
                String order = entry.getValue() == null ? "" : entry.getValue().toString().toLowerCase();
                if (APP.DESC.equals(order)) {
                    wrapper.orderByDesc(sortField);
                } else if (APP.ASC.equals(order)) {
                    wrapper.orderByAsc(sortField);
                }
            }
        }

        return page(page, wrapper);
    }

    /**
     * 获取表格数据查询条件
     * @param params        参数条件值
     * @param likeFields    like参数
     * @param equalFields   等值参数
     * @param sortFields    排序参数
     * @param inFields      in 参数
     * @return              表格数据查询条件
     */
    public QueryWrapper<T> getFormSearchWrapper(Map<String, Object> params, String[] likeFields,
                                                      String[] equalFields, Map<String,Object> sortFields, String[] inFields) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        params = ConvertUtil.humpToLines(params);
        equalFields = ConvertUtil.humpToLines(equalFields);
        likeFields = ConvertUtil.humpToLines(likeFields);
        sortFields = ConvertUtil.humpToLines(sortFields);
        inFields = ConvertUtil.humpToLines(inFields);

        if (equalFields != null) {
            for (String equalField : equalFields) {
                if (params.containsKey(equalField)) {
                    if (params.get(equalField) != null) {
                        queryWrapper.eq(equalField, params.get(equalField));
                    } else {
                        queryWrapper.isNull(equalField);
                    }
                }
            }
        }

        if (likeFields != null) {
            Map<String, Object> likePredicate = new HashMap<>(16);
            for (String likeField : likeFields) {
                if (params.containsKey(likeField) && params.get(likeField) != null) {
                    likePredicate.put(likeField, params.get(likeField));
                }
            }
            queryWrapper.and(!likePredicate.isEmpty(), wrapper -> {
               for (Map.Entry<String, Object> entry : likePredicate.entrySet()) {
                   wrapper.or().like(entry.getKey(), entry.getValue());
               }
            });
        }

        if (inFields != null) {
            for (String inField : inFields) {
                List<Object> inList = ((List<Object>) params.get(inField));
                if (inList != null && inList.size() > 0) {
                    queryWrapper.in(inField, inList);
                }
            }
        }

        if (sortFields!= null) {
            for (Map.Entry<String,Object> entry : sortFields.entrySet()) {
                String sortField = ConvertUtil.humpToLine(entry.getKey());;
                String order = entry.getValue() == null ? "" : entry.getValue().toString().toLowerCase();
                if (APP.DESC.equals(order)) {
                    queryWrapper.orderByDesc(sortField);
                } else if (APP.ASC.equals(order)) {
                    queryWrapper.orderByAsc(sortField);
                }
            }
        }
        return queryWrapper;
    }

    /**
     * 获取表格数据查询条件(like和in条件并行的情况)
     * @param params        参数条件值
     * @param likeFields    like参数
     * @param equalFields   等值参数
     * @param sortFields    排序参数
     * @param inFields      in 参数
     * @return              表格数据查询条件
     */
    public QueryWrapper<T> getFormSearchWrapperLikeAnd(Map<String, Object> params, String[] likeFields,
                                                       String[] equalFields, Map<String,Object> sortFields, String[] inFields) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        params = ConvertUtil.humpToLines(params);
        equalFields = ConvertUtil.humpToLines(equalFields);
        likeFields = ConvertUtil.humpToLines(likeFields);
        sortFields = ConvertUtil.humpToLines(sortFields);
        inFields = ConvertUtil.humpToLines(inFields);

        if (equalFields != null) {
            for (String equalField : equalFields) {
                if (params.containsKey(equalField)) {
                    if (params.get(equalField) != null) {
                        queryWrapper.eq(equalField, params.get(equalField));
                    } else {
                        queryWrapper.isNull(equalField);
                    }
                }
            }
        }

        if (likeFields != null) {
            Map<String, Object> likePredicate = new HashMap<>(16);
            for (String likeField : likeFields) {
                if (params.containsKey(likeField) && params.get(likeField) != null) {
                    likePredicate.put(likeField, params.get(likeField));
                }
            }
            queryWrapper.and(!likePredicate.isEmpty(), wrapper -> {
                for (Map.Entry<String, Object> entry : likePredicate.entrySet()) {
                    wrapper.like(entry.getKey(), entry.getValue());
                }
            });
        }

        if (inFields != null) {
            for (String inField : inFields) {
                List<Object> inList = ((List<Object>) params.get(inField));
                if (inList != null && inList.size() > 0) {
                    queryWrapper.in(inField, inList);
                }
            }
        }

        if (sortFields!= null) {
            for (Map.Entry<String,Object> entry : sortFields.entrySet()) {
                String sortField = ConvertUtil.humpToLine(entry.getKey());;
                String order = entry.getValue() == null ? "" : entry.getValue().toString().toLowerCase();
                if (APP.DESC.equals(order)) {
                    queryWrapper.orderByDesc(sortField);
                } else if (APP.ASC.equals(order)) {
                    queryWrapper.orderByAsc(sortField);
                }
            }
        }
        return queryWrapper;
    }



    /**
     * 分页查询
     *
     * @param posStart 起始位置（从0开始）
     * @param pageSize 当前页条数
     * @param wrapper  查询条件
     */
    public List<T> findPage(int posStart, int pageSize, QueryWrapper<T> wrapper) {
        IPage<T> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(posStart / pageSize + 1);

        IPage<T> pageR = page(page, wrapper);
        return pageR.getRecords();

    }

    /**
     * 分页查询
     *
     * @param currentPage 当前页码
     * @param pageSize    当前页条数
     * @param wrapper  查询条件
     */
    public IPage<T> findPageVue(int currentPage, int pageSize, QueryWrapper<T> wrapper) {
        IPage<T> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(currentPage);

        return page(page, wrapper);
    }


    /**
     * 获取记录数
     *
     * @param params      参数条件值
     * @param likeFields  like参数
     * @param equalFields 等值参数
     */
    public Integer getTotalCount(Map<String, Object> params, String[] likeFields, String[] equalFields) {
        return getTotalCount(params, likeFields, equalFields, null);
    }

    /**
     * 获取记录数
     *
     * @param params      参数条件值
     * @param likeFields  like参数
     * @param equalFields 等值参数
     * @param inFields    in 参数
     */
    public Integer getTotalCount(Map<String, Object> params, String[] likeFields, String[] equalFields, String[] inFields) {
        QueryWrapper<T> wrapper = new QueryWrapper<>();
        params = ConvertUtil.humpToLines(params);
        likeFields = ConvertUtil.humpToLines(likeFields);
        equalFields = ConvertUtil.humpToLines(equalFields);
        inFields = ConvertUtil.humpToLines(inFields);

        if (equalFields != null) {
            for (String equalField : equalFields) {
                if (params.containsKey(equalField)) {
                    if (params.get(equalField) != null) {
                        wrapper.eq(equalField, params.get(equalField));
                    } else {
                        wrapper.isNull(equalField);
                    }
                }
            }
        }
        if (likeFields != null) {
            for (String likeField : likeFields) {
                if (params.containsKey(likeField) && params.get(likeField) != null) {
                    wrapper.like(likeField, params.get(likeField));
                }
            }
        }
        if (inFields != null) {
            for (String inField : inFields) {
                if (params.containsKey(inField) && params.get(inField) != null) {
                    wrapper.in(inField, Arrays.asList(params.get(inField).toString().split(",")));
                }
            }
        }

        return super.count(wrapper);

    }

    /**
     * 单条件like值查询
     *
     * @param propertyName 属性名
     * @param value        属性值
     * @return 满足条件的所有记录
     */
    public List<T> findByPropertyLike(String propertyName, Object value) {

        QueryWrapper<T> wrapper = new QueryWrapper<>();
        if (value != null) {
            wrapper.like(ConvertUtil.humpToLine(propertyName), value);
        } else {
            wrapper.isNull(ConvertUtil.humpToLine(propertyName));
        }
        return list(wrapper);
    }

    /**
     * 分批删除数据
     * @param idList        ID列表
     * @param batchSize     每批次删除数据量的上限
     * @return
     */
    public boolean deleteBatchByIds(List<? extends Serializable> idList, int batchSize) {
        if (idList.isEmpty()) {
            return true;
        }
        int listSize = idList.size();
        int groupNum = idList.size() / batchSize + 1;
        for (int i = 0; i < groupNum; i++) {
            // 开始位置
            int fromIndex = i * batchSize;
            // 结束位置
            int toIndex = (i + 1) * batchSize < listSize ? ( i + 1 ) * batchSize : listSize;
            removeByIds(idList.subList(fromIndex, toIndex));
        }
        return true;
    }

    /**
     * 分批删除数据，每批次删除5000条
     * @param idList        ID列表
     * @return
     */
    public boolean deleteBatchByIds(List<? extends Serializable> idList) {
        return deleteBatchByIds(idList, 5000);
    }

    /**
     * 批量插入（单条SQL、回写主键）
     * @param entityList 实体对象集合
     * @return true 表示插入成功
     */
    public boolean insertBatch(Collection<T> entityList) {
        return SqlHelper.retBool(insertBatchSomeColumn(entityList));
    }

    /**
     * 批量插入（单条SQL、回写主键）
     * @param entityList 实体对象集合
     * @return 成功条数
     */
    public Integer insertBatchSomeColumn(Collection<T> entityList){
        return insertBatchSomeColumn(entityList,1000);
    }


    /**
     * 批量插入（单条SQL、回写主键）
     * @param entityList 实体对象集合
     * @param batchSize 每次插入的数量
     * @return 成功条数
     */
    @Transactional(rollbackFor = Exception.class)
    public Integer insertBatchSomeColumn(Collection<T> entityList,int batchSize) {

        if (entityList == null || entityList.isEmpty()) {
            return 0;
        }
        List<T> batchList = new ArrayList<>();
        int successRow = 0;
        for (T entity : entityList) {
            batchList.add(entity);
            if (batchList.size() % batchSize == 0) {
                successRow += getBaseMapper().insertBatchSomeColumn(batchList);
                batchList.clear();
            }
        }
        if (batchList.size() > 0) {
            successRow += getBaseMapper().insertBatchSomeColumn(batchList);
        }
        return successRow;
    }

    /**
     * 批量修改插入（回写主键）
     *
     * @param entityList 实体对象集合
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean insertOrUpdateBatch(Collection<T> entityList) {
        return insertOrUpdateBatch(entityList, 1000);
    }

    /**
     * 批量修改插入（回写主键）
     *
     * @param entityList 实体对象集合
     * @param batchSize  每次的数量
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean insertOrUpdateBatch(Collection<T> entityList, int batchSize) {
        Assert.notEmpty(entityList, "error: entityList must not be empty");
        Class<?> cls = currentModelClass();
        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
        Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
        String keyProperty = tableInfo.getKeyProperty();
        Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");

        List<T> insertList = new ArrayList<>();
        List<T> updateList = new ArrayList<>();
        for (T entity : entityList) {
            Object idVal = ReflectionKit.getMethodValue(cls, entity, keyProperty);
            if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) {
                insertList.add(entity);
            } else {
                updateList.add(entity);
            }
        }
        if (insertList.size() > 0) {
            //批量插入
            insertBatchSomeColumn(insertList, batchSize);
        }
        if (updateList.size() > 0) {
            //批量更新
            updateBatchById(updateList, batchSize);
        }
        return true;
    }

    /**
     * 创建数据库
     * @param newActualDatabaseName 数据库名
     * @return 匹配行数
     */
    protected Integer createDatabaseIfAbsent(String newActualDatabaseName) {
        return getBaseMapper().createDatabaseIfAbsent(newActualDatabaseName);
    }

    /**
     * 根据现有的表创建新的分表(复制表结构)
     * @param newActualDatabaseName 新的实际数据库名
     * @param newActualTableName 新的实际表名
     * @param originalDatabaseName 现有数据库名
     * @param originalTableName 现有表名
     */
    protected void createTableIfAbsentLikeOldTable(String newActualDatabaseName, String newActualTableName, String originalDatabaseName, String originalTableName) {
        getBaseMapper().createTableIfAbsentLikeOldTable(newActualDatabaseName, newActualTableName, originalDatabaseName, originalTableName);
    }

    /**
     * 从指定数据库中，查询是否存在某张表
     *
     * @param databaseName 实际数据库名
     * @param tableName 实际表名
     * @return 结果记录数（表存在正常结果是1）
     */
    protected Integer isTableExist(String databaseName, String tableName) {
        return getBaseMapper().isTableExist(databaseName, tableName);
    }

    /**
     * 组装分页表格数据
     *
     * @param page    IPage
     * @param rowList 行数据集合
     * @return
     */
    public Map<String, Object> getPageResult(IPage<T> page, List<Map<String, Object>> rowList) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put(APP.DATA, rowList);
        resultMap.put(APP.TOTAL_COUNT, page.getTotal());
        resultMap.put(APP.POS, (page.getCurrent() - 1) * page.getSize());
        resultMap.put(APP.CURRENT_PAGE, page.getCurrent());
        return resultMap;
    }

    /**
     * 空的分页
     * @return
     */
    public Map<String, Object> getEmptyPageResult() {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put(APP.DATA, new ArrayList<>());
        resultMap.put(APP.TOTAL_COUNT, 0);
        resultMap.put(APP.POS, 0);
        resultMap.put(APP.CURRENT_PAGE, 1);
        return resultMap;
    }

    /**
     * 单条件in查询
     * @param inField
     * @param valueList
     * @return
     */
    public List<T> findListByProperty(SFunction<T, ?> inField, Collection<? extends Serializable> valueList) {
        if(valueList.isEmpty()){
            return new ArrayList<>();
        }
        LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(inField, valueList);
        return list(wrapper);
    }
}
